function startSpeechInput() {
	chrome.experimental.speechInput.onError.addListener(recognitionFailed);
	chrome.experimental.speechInput.onResult.addListener(recognitionSucceeded);
	chrome.experimental.speechInput.onSoundEnd.addListener(recognitionEnded);
	
	chrome.experimental.speechInput.isRecording(function (isRecording) {
		if (isRecording !== true) {
			chrome.experimental.speechInput.start({ 'language': 'de' }, function(){
					var audioElementStart = document.createElement('audio');
					audioElementStart.setAttribute('src', './Audi_MMI_Files/media/ding.wav');
					audioElementStart.volume = 0.2;
					audioElementStart.play();

					if (chrome.extension.lastError) {
						console.log("Couldn't start speech input: " + chrome.extension.lastError.message);
					}
					
					console.log("Voice recognition started!");
			});
		}
		else {
			console.log('Pressed Record while it is already recording. Do nothing...');
		}
	});
}

function recognitionEnded() {
	var audioElementEnd = document.createElement('audio');
	audioElementEnd.setAttribute('src', './Audi_MMI_Files/media/ding.wav');
	audioElementEnd.volume = 0.2;
	audioElementEnd.play();
}

	function getStarImage(avgRating){
		var ret;
		if (avgRating == 1) { 
              ret='<img src="./images/sterne_Ranking/1sterne_gross.png">';	
		}
		else if (avgRating == 2) { 
              ret='<img src="./images/sterne_Ranking/2sterne_gross.png">';	
		}
		else if (avgRating == 3) { 
              ret='<img src="./images/sterne_Ranking/3sterne_gross.png">';	
		}
		else if (avgRating == 4) { 
              ret='<img src="./images/sterne_Ranking/4sterne_gross.png">';	
		}
		else if (avgRating == 5) { 
              ret='<img src="./images/sterne_Ranking/5sterne_gross.png">';	
		}
		return ret;
	}

function recognitionFailed(error) {
	var audioElementEnd = document.createElement('audio');
	audioElementEnd.setAttribute('src', './Audi_MMI_Files/media/mic_end.mp3');
	audioElementEnd.volume = 0.2;
	audioElementEnd.play();
	console.log('Speech input failed: ' + error.code);
}

//Hashtable implementation (if you use an object there are some drawbacks e.g ht['key'] is an object and there are no lenght attribute)
function HashTable(obj)
{
    this.length = 0;
    this.items = {};
    for (var p in obj) {
        if (obj.hasOwnProperty(p)) {
            this.items[p] = obj[p];
            this.length++;
        }
    }

    this.setItem = function(key, value)
    {
        var previous = undefined;
        if (this.hasItem(key)) {
            previous = this.items[key];
        }
        else {
            this.length++;
        }
        this.items[key] = value;
        return previous;
    }

    this.getItem = function(key) {
        return this.hasItem(key) ? this.items[key] : undefined;
    }

    this.hasItem = function(key)
    {
        return this.items.hasOwnProperty(key);
    }
   
    this.removeItem = function(key)
    {
        if (this.hasItem(key)) {
            previous = this.items[key];
            this.length--;
            delete this.items[key];
            return previous;
        }
        else {
            return undefined;
        }
    }

    this.keys = function()
    {
        var keys = [];
        for (var k in this.items) {
            if (this.hasItem(k)) {
                keys.push(k);
            }
        }
        return keys;
    }

    this.values = function()
    {
        var values = [];
        for (var k in this.items) {
            if (this.hasItem(k)) {
                values.push(this.items[k]);
            }
        }
        return values;
    }

    this.each = function(fn) {
        for (var k in this.items) {
            if (this.hasItem(k)) {
                fn(k, this.items[k]);
            }
        }
    }

    this.clear = function()
    {
        this.items = {}
        this.length = 0;
    }
	
}